package com.duanjw.springframework.aop;

import com.duanjw.springframework.aop.config.AppConfig;
import com.duanjw.springframework.aop.dao.UserDao;
import com.duanjw.springframework.aop.dao.impl.UserDaoImpl;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * aop应用
 *
 * @author duanjw
 */
public class AopApplication {
    public static void main(String[] args) {
        ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
        //Exception in thread "main" org.springframework.beans.factory.NoSuchBeanDefinitionException:
        // No qualifying bean of type 'com.duanjw.springframework.aop.com.duanjw.springframework.dao.impl.UserDaoImpl' available
//        UserDao userDao = (UserDao)ctx.getBean(UserDaoImpl.class);
//        userDao.query();
        UserDao bean = (UserDao)ctx.getBean("userDaoImpl");
        AppConfig appConfig = ctx.getBean(AppConfig.class);
        System.out.println(bean);
        bean.query();
        System.out.println("---------");
//        bean.query("张三");
//        System.out.println("---------");

//        UserDao testUserDaoImpl = (UserDao)ctx.getBean("testUserDaoImpl");
//        testUserDaoImpl.query();
    }
}
